<script>
import wx from 'wx'
import api from '@/utils/api'
import util from '@/utils/util'
export default {
  mpType: 'app',
  created () {
    this.getUserInfo() // 检测用户是否登录过
  },
  methods: {
    getUserInfo () {
      console.log('App.vue执行了')
      const that = this
      const userInfo = wx.getStorageSync('userInfo')
      if (userInfo) {
        util.checkSession().then((e) => {
          console.log(e)
          // 将用户信息注册到全局变量
          that.$mp.app.globalData.userInfo = userInfo
          // 跳转到动态页
          wx.switchTab({
            url: '/pages/basic/dynamic/dynamic'
          })
        }).catch((err) => {
          console.log(err)
          that.getwxlogin() // 获取登录态
        })
      } else {
        that.getwxlogin() // 获取登录态
      }
    },
    getwxlogin () {
      util.login().then(async (res) => {
        const code = res.code
        const resInfo = await api.wxlogin({
          code
        })
        if (resInfo.errno === 0) {
          wx.setStorageSync('token', resInfo.data.token)
        } else {
          console.log(resInfo.data)
        }
      }).catch((err) => {
        console.log(err)
      })
    }
  }

}
</script>
<style>
page {
  height: 100%;
  background: rgba(153, 153, 153, 0.1);
  font-family: "-apple-system-font", "Helvetica Neue", "Helvetica", "sans-serif" !important;
}
.container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  box-sizing: border-box;
  font-family: "-apple-system-font", "Helvetica Neue", "Helvetica", "sans-serif" !important;
}
/* reset */
view,
div {
  box-sizing: border-box;
  font-family: "-apple-system-font", "Helvetica Neue", "Helvetica", "sans-serif" !important;
}
.flex {
  display: flex;
  align-items: center;
  justify-content: center;
}
.flex-item {
  flex: 1;
}
.flex-column {
  flex-direction: column;
}
.background-image {
  background-position: 50%;
  background-size: cover;
  background-repeat: no-repeat;
}
.mask {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1;
}
.bottom {
  font-size: 24rpx;
  color: #999999;
}
.tl {
  text-align: left;
}
.tc {
  text-align: center;
}
.tr {
  text-align: right;
}
/* 表格 */
#panel {
  width: 100%;
  background: #fff;
  position: relative;
  padding-left: 200rpx;
}

#panel text {
  border-bottom: 2rpx solid #ddd;
}
.table-content {
  display: flex;
  width: 100%;
}
.tr,
.th {
  display: inline-flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}
.td {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  line-height: 60rpx;
  font-size: 24rpx;
  width: 150rpx;
  text-align: center;
}

.flex-cell {
  flex: 1;
}
.flex-fixed {
  position: absolute;
  top: 0;
  left: 0;
  width: 200rpx;
  box-shadow: 4rpx 4rpx 4rpx rgba(153, 153, 153, 0.2);
}
.flex-fixed .fixed-text {
  width: 100%;
  display: block;
  height: 80rpx;
  line-height: 80rpx;
  font-size: 24rpx;
  border-bottom: 2rpx solid #ddd;
  text-align: center;
}
.scroll-view {
  flex: 1;
}
#panel2 {
  width: 100%;
  background: #fff;
  position: relative;
}

#panel2 text {
  border-bottom: 2rpx solid #ddd;
}
.db {
  display: block;
  height: 80rpx;
  line-height: 80rpx;
}
.db_table {
  display: inline-block;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  font-size: 24rpx;
  width: 150rpx;
  text-align: center;
}
/* press */
.press::before {
  content: " ";
  position: absolute;
  top: 50%;
  left: 50%;
  opacity: 0;
  width: 100%;
  height: 100%;
  border: inherit;
  border-color: #000;
  background-color: #000;
  border-radius: inherit;
  transform: translate(-50%, -50%);
}
.press:active::before {
  opacity: 0.15;
}
</style>